package org.nfyszny.zzzs.modules.controller;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoDict;
import org.jeecg.common.system.query.QueryGenerator;

import org.nfyszny.zzzs.modules.entity.ZzzsPestAndDiseaseControl;
import org.nfyszny.zzzs.modules.service.IZzzsPestAndDiseaseControlService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;


import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 病虫害防治
 * @Author: jeecg-boot
 * @Date:   2022-11-10
 * @Version: V1.0
 */
@Api(tags="病虫害防治")
@RestController
@RequestMapping("/modules/zzzsPestAndDiseaseControl")
@Slf4j
public class ZzzsPestAndDiseaseControlController extends JeecgController<ZzzsPestAndDiseaseControl, IZzzsPestAndDiseaseControlService> {
	@Autowired
	private IZzzsPestAndDiseaseControlService zzzsPestAndDiseaseControlService;
	
	/**
	 * 分页列表查询
	 *
	 * @param zzzsPestAndDiseaseControl
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "病虫害防治-分页列表查询")
	@ApiOperation(value="病虫害防治-分页列表查询", notes="病虫害防治-分页列表查询")
	@GetMapping(value = "/list")
	@AutoDict
	public Result<IPage<ZzzsPestAndDiseaseControl>> queryPageList(ZzzsPestAndDiseaseControl zzzsPestAndDiseaseControl,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<ZzzsPestAndDiseaseControl> queryWrapper = QueryGenerator.initQueryWrapper(zzzsPestAndDiseaseControl, req.getParameterMap());
		Page<ZzzsPestAndDiseaseControl> page = new Page<ZzzsPestAndDiseaseControl>(pageNo, pageSize);
		IPage<ZzzsPestAndDiseaseControl> pageList = zzzsPestAndDiseaseControlService.pageList(page, queryWrapper);
		return Result.TOK(pageList);
	}
	 /**
	  * 切换显示状态
	  */
	 @GetMapping("switchStatus")
	 public Result switchStatus(@RequestParam String id,@RequestParam Integer status) {
		 zzzsPestAndDiseaseControlService.switchStatus(id,status);
		 return Result.TOK();
	 }
	/**
	 *   添加
	 *
	 * @param zzzsPestAndDiseaseControl
	 * @return
	 */
	@AutoLog(value = "病虫害防治-添加")
	@ApiOperation(value="病虫害防治-添加", notes="病虫害防治-添加")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_pest_and_disease_control:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody ZzzsPestAndDiseaseControl zzzsPestAndDiseaseControl) {
		zzzsPestAndDiseaseControlService.save(zzzsPestAndDiseaseControl);
		return Result.TOK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param zzzsPestAndDiseaseControl
	 * @return
	 */
	@AutoLog(value = "病虫害防治-编辑")
	@ApiOperation(value="病虫害防治-编辑", notes="病虫害防治-编辑")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_pest_and_disease_control:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody ZzzsPestAndDiseaseControl zzzsPestAndDiseaseControl) {
		zzzsPestAndDiseaseControlService.updateById(zzzsPestAndDiseaseControl);
		return Result.TOK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "病虫害防治-通过id删除")
	@ApiOperation(value="病虫害防治-通过id删除", notes="病虫害防治-通过id删除")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_pest_and_disease_control:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		zzzsPestAndDiseaseControlService.removeById(id);
		return Result.TOK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "病虫害防治-批量删除")
	@ApiOperation(value="病虫害防治-批量删除", notes="病虫害防治-批量删除")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_pest_and_disease_control:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.zzzsPestAndDiseaseControlService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.TOK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "病虫害防治-通过id查询")
	@ApiOperation(value="病虫害防治-通过id查询", notes="病虫害防治-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<ZzzsPestAndDiseaseControl> queryById(@RequestParam(name="id",required=true) String id) {
		ZzzsPestAndDiseaseControl zzzsPestAndDiseaseControl = zzzsPestAndDiseaseControlService.getById(id);
		if(zzzsPestAndDiseaseControl==null) {
			return Result.error("未找到对应数据");
		}
		return Result.TOK(zzzsPestAndDiseaseControl);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param zzzsPestAndDiseaseControl
    */
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_pest_and_disease_control:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ZzzsPestAndDiseaseControl zzzsPestAndDiseaseControl) {
        return super.exportXls(request, zzzsPestAndDiseaseControl, ZzzsPestAndDiseaseControl.class, "病虫害防治");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("zzzs_pest_and_disease_control:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ZzzsPestAndDiseaseControl.class);
    }

}
